//
//  UIButton+BCWebImage.m
//  BCWebImageKit
//
//  Created by Basic on 2018/5/24.
//  UIButton web图片加载扩展

#import "UIButton+BCWebImage.h"
// SDWEBIMAGE_INNER，表示是否使用内嵌的sdwebimage，在podspec里定义
#ifdef SDWEBIMAGE_INNER
#import "UIButton+WebCache.h"
#else
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunknown-warning-option"
#pragma clang diagnostic ignored "-Wstrict-prototypes"
#import <SDWebImage/UIButton+WebCache.h>
#pragma clang diagnostic pop
#endif


@implementation UIButton (BCWebImage)

//MARK: - Image
- (void)bc_setImageWithURL:(nullable NSString *)urlStr forState:(UIControlState)state {
    NSURL *url = (urlStr.length>0)?[NSURL URLWithString:urlStr]:nil;
    [self sd_setImageWithURL:url forState:state];
}

- (void)bc_setImageWithURL:(nullable NSString *)urlStr forState:(UIControlState)state placeholderImage:(nullable UIImage *)placeholder {
    NSURL *url = (urlStr.length>0)?[NSURL URLWithString:urlStr]:nil;
    [self sd_setImageWithURL:url forState:state placeholderImage:placeholder];
}

//MARK: - Background image
- (void)bc_setBackgroundImageWithURL:(nullable NSString *)urlStr forState:(UIControlState)state {
    NSURL *url = (urlStr.length>0)?[NSURL URLWithString:urlStr]:nil;
    [self sd_setBackgroundImageWithURL:url forState:state];
}
- (void)bc_setBackgroundImageWithURL:(nullable NSString *)urlStr forState:(UIControlState)state placeholderImage:(nullable UIImage *)placeholder {
    NSURL *url = (urlStr.length>0)?[NSURL URLWithString:urlStr]:nil;
    [self sd_setBackgroundImageWithURL:url forState:state placeholderImage:placeholder];
}

//MARK: - 取消
- (void)bc_cancelImageLoadForState:(UIControlState)state {
    [self sd_cancelImageLoadForState:state];
}

- (void)bc_cancelBackgroundImageLoadForState:(UIControlState)state {
    [self bc_cancelBackgroundImageLoadForState:state];
}

@end
